<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录页面</title>
    <script src="./js/jquery.js"></script>
</head>
<body>
    <h2>L&Y请您登录</h2>
    <form action="" id="frmlogin">
        <p>
            <label for="username">账号：</label>
            <input type="text" name="username" id="username">
        </p>
        <p>
            <label for="password">密码：</label>
            <input type="password" name="password" id="password">
        </p>
        <p>
            <input type="button" value="登录" id="btnLogin">
        </p>
    </form>
</body>
<script>
    $('#btnLogin').click(function(){
        $.ajax({
            type: 'post',
            url: '/login',
            data: $('#frmLogin').serialize() 
        }).then(res=>{
            if(res.msg === 'ok'){
                location.href='./index.html';
            }else{
                alert('您输入的账号或密码错误，请重新输入！');
                $('#username').val('');
                $('#password').val('');
                $('#username').focus();
            }
        });
    });
</script>
</html>